﻿#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->pushButtonZhangSan, &QPushButton::clicked, this, &MainWindow::FoodIsComing);
    connect(ui->pushButtonLiSi, &QPushButton::clicked, this, &MainWindow::FoodIsComing);
    connect(ui->pushButtonWangWu, &QPushButton::clicked, this, &MainWindow::FoodIsComing);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::FoodIsComing()
{
    //获取信号源头对象的名称
    QString strObjectSrc = this->sender()->objectName();
    qDebug()<<strObjectSrc; //打印源头对象名称

    //将要显示的消息
    QString strMsg;
    //判断是哪个按钮发的信号
    if( "pushButtonZhangSan" == strObjectSrc )
    {
        strMsg = tr("Hello Anderson! Your food is coming!");
    }
    else if( "pushButtonLiSi" == strObjectSrc )
    {
        strMsg = tr("Hello Bruce! Your food is coming!");
    }
    else if( "pushButtonWangWu" == strObjectSrc )
    {
        strMsg = tr("Hello Castiel! Your food is coming!");
    }
    else
    {
        //do nothing
        return;
    }
    //显示送餐消息
    QMessageBox::information(this, tr("Food"), strMsg);
}
